package com.itheima.jobs;

import com.itheima.contast.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;


/**
 * @author Gallant
 * @create 2020-07-03 12:16
 */
public class ClearImgJob {

    @Autowired
    private JedisPool jedisPool;
    public void clearImg(){
        // 求出两个图片集合中的差值
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        // 对集合遍历
        if (set != null){
            for (String picName : set) {
                // 从七牛云上将图片删除掉
                QiniuUtils.deleteFileFromQiniu(picName);
                // 从redis中将信息也删除掉
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES, picName);
            }
        }
    }
}
